<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>招领管理</title>
    <meta name="description" content="招领管理">
    <meta name="keywords" content="招领管理">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="./plugins/elementui/index.css">
    <link rel="stylesheet" href="./plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="./css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/vue.js"></script>
    <script src="./plugins/elementui/index.js"></script>
    <script src="./js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td,
        .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>

<body class="hold-transition">
    <div id="app">
        <div class="content-header">
            <h1>招领管理</h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>招领管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="app-container">
            <div class="box">
                <div class="filter-container">
                    <el-input placeholder="员工姓名" v-model="pagination.queryString" style="width: 200px;"
                        class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleCreate()">发招招领</el-button>
                </div>
                <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                    <el-table-column prop="title" label="标题" align="center"></el-table-column>
                    <el-table-column prop="image" label="图片" align="center">
                        <template slot-scope="scope">
                            <img :src="scope.row.image" style="height: 50px;">
                        </template>
                    </el-table-column>
                    <!-- <el-table-column prop="releaseTime" label="发布时间" align="center"></el-table-column>                     -->
                    <el-table-column prop="collectTime" label="丢失时间" align="center"></el-table-column>
                    <el-table-column prop="collectPlace" label="丢失地点" align="center"></el-table-column>
                    <el-table-column prop="contacts" label="联系人" align="center"></el-table-column>
                    <el-table-column prop="phoneNumber" label="联系人电话" align="center"></el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" size="mini" @click="handleEdit(scope.row.id)">编辑</el-button>
                            <el-button size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-container">
                    <el-pagination class="pagiantion" @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage" :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper" :total="pagination.total">
                    </el-pagination>
                </div>
                <!-- 新增标签弹层 -->
                <div class="add-form">
                    <el-dialog title="发布" :visible.sync="dialogFormVisible">
                        <template>
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="物品信息" name="first">
                                    <el-form label-position="right" label-width="100px">
<!--                                         <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="发布类别">
                                                    <el-input v-model="formData.category" :value="'失物招领'"
                                                        disabled></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row> -->
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="物品类别">
                                                    <el-input v-model="formData.name" />
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="物品标题">
                                                    <el-input v-model="formData.title" />
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="丢失时间">
                                                    <el-date-picker v-model="formData.localDate" type="date"
                                                        placeholder="选择日期">
                                                    </el-date-picker>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="上传图片">
                                                    <el-upload class="avatar-uploader" action="/upload"
                                                        :auto-upload="autoUpload" name="image" :show-file-list="false"
                                                        :on-success="handleAvatarSuccess"
                                                        :before-upload="beforeAvatarUpload">
                                                        <img :src="formData.image" class="avatar">
                                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                                    </el-upload>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="20">
                                                <el-form-item label="物品介绍">
                                                    <el-input v-model="formData.article" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>

                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="丢失地点">
                                                    <el-input v-model="formData.localPlace" />
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="联系人">
                                                    <el-input v-model="formData.contacts" />
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="联系人电话">
                                                    <el-input v-model="formData.phoneNumber" />
                                                </el-form-item>
                                            </el-col>
                                        </el-row>


                                    </el-form>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible = false">取消</el-button>
                            <el-button type="primary" @click="handleAdd()">确定</el-button>
                        </div>
                    </el-dialog>
                </div>

            </div>
        </div>
    </div>
</body>

<script>
    let vue = new Vue({
        el: '#app',
        data: {
            autoUpload: true,//自动上传
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中检查组列表数据
            EmpIds: [],//添加表单窗口中检查组复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,
        },
        created() {
            this.findPage();

        },
        mounted() {
                this.formData.category = '失物招领';
                this.formData.image = response.data;
        },

        methods: {
            //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
            handleAvatarSuccess(response) {           
                this.formData.image = response.data;
            },
            //上传图片之前执行
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isJPG) {
                    this.$message.error('上传套餐图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传套餐图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },
            //添加
            handleAdd() {
                this.formData.category = '失物招领';
                axios.post(`/recruit/${this.formData.id == null ? 'add' : 'update'}?ids=${this.EmpIds}`, this.formData).then(response => {
                    this.formData = response.data;
                    if (response.data.code == 1) {
                        this.dialogFormVisible = false;
                        this.findPage();
                        this.$message.success(response.data.message);
                    } else {
                        this.dialogFormVisible = false;
                        this.$message.error("数据有误,请检查");
                    }
                })
            },
            //分页查询
            findPage() {

                let params = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString,

                };
                axios.post(`/recruit`, params).then(response => {
                    this.dataList = response.data.data.rows;
                    console.log(response.data.data.rows);
                    this.pagination.total = response.data.data.total;
                })
            },
            // 重置表单
            resetForm() {
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.activeName = "first";
                this.formData = {};
                this.formData.image = response.data

            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            handleEdit(id) {
                //弹出编辑窗口
                this.dialogFormVisible = true;
                this.activeName = "first";
                axios.get(`/recruit/findById?id=${id}`).then(response => {
                    this.formData = response.data;

                });


            },
            handleDelete(id) {
                this.$confirm('是否删除该物品信息?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post(`/recruit/delete?id=${id}`).then(response => {
                        if (response.data.code == 1) {
                            this.$message.success("删除成功");
                            this.findPage();
                        } else {
                            this.$message.error("服务器异常");
                        }
                    })
                }).catch(() => {

                });
            }
        }
    })
</script>

</html>